<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>23.不允许向对象中添加属性API</title>
</head>

<body>
  <script>
    //禁止添加属性
    "use strict";
    const user = {
      name: "向军"
    };
    Object.preventExtensions(user);
    //Object.isExtensible 判断是否能向对象中添加属性
    if (Object.isExtensible(user))
      user.age = 18; //    // 严格模式下会报错，非严格模式也不能添加属性 Uncaught TypeError: Cannot add property age, object is not extensible
    else 
    console.log(Object.isExtensible(user)); //false


  </script>
</body>

</html>